#ifndef SINGLEINSTANCEGRARD_H
#define SINGLEINSTANCEGRARD_H

#include <QObject>
#include <qsharedmemory.h>
#include <QtCore/qglobal.h>

#if defined(SINGLEINSGUARD_LIBRARY)
#  define SINGLEINSGUARD_EXPORT Q_DECL_EXPORT
#else
#  define SINGLEINSGUARD_EXPORT Q_DECL_IMPORT
#endif

class SINGLEINSGUARD_EXPORT SingleInstanceGuard final
{
public:
    SingleInstanceGuard(const QString&key);
    ~SingleInstanceGuard();
    bool IsPrimary() const{return m_is_primary;}
private:
    void KillExitingInstance();
private:
    bool m_is_primary{false};
    QString m_mem_lock_key{};
    QString m_shared_mem_key{};
    QSharedMemory m_memory{};
};

#endif // SINGLEINSTANCEGRARD_H
